package com.scsj.supermarket.model;

import android.content.Context;
import android.util.Log;

import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.RegisterBase;
import com.scsj.supermarket.bean.RegisterBean;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 注册
 */

public class RegisterPresenter extends BasePresenter implements RegisterBase.IPresenter {

    private RegisterBase.IView mView;
    private RegisterBase.IModel mModel;

    public RegisterPresenter(RegisterBase.IView mView) {
        this.mView = mView;
        mModel = new RegisterModel();
    }

    @Override
    public void deliverData(Context context,RequestBody requestBody) {

        addSubscription(mModel.getData(context, requestBody, new ResponseCallback<RegisterBean>() {
            @Override
            public void onSuccess(RegisterBean result) {

                if (result.getStatusCode() == 200) {
                    if (result.getStatusCode() == 200) {
                        mView.showSuccessMsg("获取成功", result);
                        Logger.e("获取成功" + result.toString());
                    } else {
                        mView.showErrorMsg(result.getMsg());
                        Logger.e("未成功" + result.toString());
                    }
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("失败", msg + "");
            }
        }));
    }
}
